package com.echoesnet.echoesshortvideo.Utils;

import com.liulishuo.okdownload.DownloadListener;
import com.liulishuo.okdownload.DownloadTask;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/5/5 11:04
 * @description
 */
public class DownLoadUtil
{
    private DownloadTask task;

    private DownLoadUtil()
    {



    }
    //在访问DownLoadUtil时创建单例
    private static class SingletonHolder
    {
        private static final DownLoadUtil INSTANCE = new DownLoadUtil();
    }

    //获取单例
    public static DownLoadUtil getInstance()
    {
        return DownLoadUtil.SingletonHolder.INSTANCE;
    }

    /**
     * 下载文件
     * @param url 远程文件url
     * @param filePath 下载的文件的存储路径
     * @param fileName 下载的文件的文件名称
     * @param dListener 下载监听，可以跟进需求使用如下骨架类中的一个，每个产生的回调都不同，根据自己的需求使用，其中DownloadListener 是一个接口，
     *                   回调方法是最全的，但是一般用不到，回调都是UI线程，可以直接操作UI。
     * @see com.liulishuo.okdownload.core.listener.DownloadListener1
     * @see com.liulishuo.okdownload.core.listener.DownloadListener2
     * @see com.liulishuo.okdownload.core.listener.DownloadListener3
     * @see com.liulishuo.okdownload.core.listener.DownloadListener4
     * @see com.liulishuo.okdownload.core.listener.DownloadListener4WithSpeed
     */
    public void downloadFile(String url, String filePath,String fileName,DownloadListener dListener)
    {
       DownloadTask task = new DownloadTask.Builder(url, filePath,fileName)
                // the minimal interval millisecond for callback progress
                .setMinIntervalMillisCallbackProcess(500)
                // do re-download even if the task has already been completed in the past.
                .setPassIfAlreadyCompleted(false)
                .build();
       task.enqueue(dListener);
    }


}
